package ar.edu.unicen.pladema.vc1.practico1;

import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;

import ar.edu.unicen.pladema.ui.model.ColorProgress;
import ar.edu.unicen.pladema.vc1.model.GraphicAttributes;
import ar.edu.unicen.pladema.vc1.practico.PracticoDrawer;

public class P1Enunciado2Drawer extends PracticoDrawer {

	private int width;
	private int height;
	private ColorProgress cp;
	public P1Enunciado2Drawer(GraphicAttributes ga) {
		super(ga);

		cp = new ColorProgress(new RGB(0,0,0), new RGB(255,255,255));
	}
	@Override
	public void paintControlImpl(PaintEvent e) {
		this.width = graphicAttributes.getInt(GraphicAttributes.CLIENT_WIDTH);
		this.height = graphicAttributes.getInt(GraphicAttributes.CLIENT_HEIGHT);
		
		Double diagonal = Math.sqrt((width*width)+(height*height));
		
		for (int i=0; i<width; i++ ) {
			for (int j=0; j<height; j++) {
				Double step = Math.sqrt((i*i)+(j*j));
				RGB color = cp.getColorAt(diagonal.intValue(), 0, step.intValue());
				//int d =255* (i+j)/(width+height);//dd0
				Color c = new Color (e.gc.getDevice(), color);
				e.gc.setForeground(c);
				e.gc.drawPoint(i, j);
			}
		}
		
	}

	public void setColors(RGB inicio, RGB fin) {
		cp = new ColorProgress(inicio, fin);
	}

}
